package com.wasion.pwportable.protocol.analyzer.indicator;

import com.wasion.pwportable.protocol.Protocol;
import com.wasion.pwportable.protocol.analyzer.AbstractAnalyzer;

/**
 * 
 * @ClassName: Short_OverFlow_RD_Analyzer
 * @Description: 2C. 运行参数相关信息, 短路速断电流...
 * @author 高意
 * @date 2014-9-11 上午10:04:54
 * 
 */
public class Short_OverFlow_RD_Analyzer extends AbstractAnalyzer {

	@Override
	public void dataAnalysis(String ackBS) {

		String data = ackBS.substring(DATABITSTART, DATABITSTART + 2);
		int currentInt = Integer.parseInt(data, 16) * Protocol.CURRENT_CAL_REF; // 是5电流计算系数

		result.setShortCut(currentInt);

		data = ackBS.substring(DATABITSTART + 2, DATABITSTART + 6);
		String cutOffTime = data.substring(2, 4) + data.substring(0, 2);
		int cTimeInt = Integer.parseInt(cutOffTime, 16);
		result.setShortCutTime(cTimeInt);

		data = ackBS.substring(DATABITSTART + 6, DATABITSTART + 8);
		int overCurrentInt = Integer.parseInt(data, 16)
				* Protocol.CURRENT_CAL_REF;
		result.setShortOverFlow(overCurrentInt);

		data = ackBS.substring(DATABITSTART + 8, DATABITSTART + 12);
		String overTime = data.substring(2, 4) + data.substring(0, 2);
		int oTimeInt = Integer.parseInt(overTime, 16);
		result.setShortOverFlowTime(oTimeInt);

		// 复归时间
		data = ackBS.substring(DATABITSTART + 12, DATABITSTART + 14);
		int dataInt = Integer.parseInt(data, 16); // 10 进制 数
		String dataBinery = Integer.toBinaryString(dataInt); // 传唤成2进制 字符串

		// 高位补0
		while (dataBinery.length() < 8) {
			dataBinery = "0" + dataBinery;
		}

		String turnBackMode = dataBinery.substring(0, 1);

		if (turnBackMode.equals("1")) {
			result.setTurnBackMode(1);

			result.setTurnBackTime(0);
			// result.setTurnBackUnit(0);
		}

		else if (turnBackMode.equals("0")) {
			result.setTurnBackMode(0);

			String timeUnit = dataBinery.substring(1, 2);

			if (timeUnit.equals("1")) {
				result.setTurnBackUnit(1); // 小时
			} else {
				result.setTurnBackUnit(0);// 分钟
			}

			String turnBackTime = dataBinery.substring(2, 8);

			int time = Integer.parseInt(turnBackTime, 2);
			result.setTurnBackTime(time);
		}
	}
}
